<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-user"></i> 商家入驻列表 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                店铺名称：
                <el-input v-model="name" placeholder="请输入店铺名称" class="handle-input mr10"  @keyup.enter.native="handleSearch"></el-input>
                审核状态：
                <el-select v-model="value" placeholder="请选择状态" @change="change">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" > </el-option>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch" style="margin-left: 20px;">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="f_name" label="商家姓名"></el-table-column>  
                <el-table-column prop="f_phone" label="联系电话"></el-table-column>
                <el-table-column prop="f_shop_name" label="店铺名称"></el-table-column>
                <el-table-column label="开店城市">
                    <template slot-scope="scope">{{ scope.row.f_provinces }}{{ scope.row.f_city }}{{ scope.row.f_area }}</template>
                </el-table-column>
                <el-table-column prop="f_address" label="详细地址"></el-table-column>
                <el-table-column label="开店预算">
                    <template slot-scope="scope">￥{{ scope.row.f_money }}</template>
                </el-table-column>
                <el-table-column label="审核状态" align="center">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.f_status == 0">申请中</el-tag>
                        <el-tag v-if="scope.row.f_status == 1"  type="success">已通过</el-tag>
                        <el-tag v-if="scope.row.f_status == 2" type="danger">被驳回</el-tag>
                    </template>
                </el-table-column>

                <el-table-column prop="f_remark" label="备注"></el-table-column>
                <el-table-column prop="created_at" label="登记时间"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope"  v-if="scope.row.f_status == 0">
                        <el-button type="text" icon="el-icon-check" class="green" @click="Applylist(scope.row)">通过</el-button>
                        <el-button type="text" icon="el-icon-close" class="red" @click="reject(scope.row)">拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.pageNum"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <el-dialog title="查看弹窗" :visible.sync="editVisible" width="500px" append-to-body>
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="商家姓名">
                    <el-input v-model="form.f_name">{{ form.name }}</el-input>
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="form.f_phone"></el-input>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { apply, opApply } from '../../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            // 是否显示弹出层
            open: false,
            query: {
                page: 1,
                pageNum: 15,
                // status: 1
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            checkList: [],
            name: '', 
            options: [
                {
                    value: '0',
                    label: '申请中'
                },
                {
                    value: '1',
                    label: '已通过'
                },
                {
                    value: '2',
                    label: '已驳回'
                }
            ],
            value: '',
            status:'',
        };
    },
    created() {
        this.getData();  
    },
    methods: {
        change(e){
            console.log(e)
            this.status = e
        },
        // 获取 easy-mock 的模拟数据
        getData() {
            apply(this.query).then((res) => {
                console.log(res.data.list);
                this.tableData = res.data.list;
                this.pageTotal = res.data.count || 50;
            });
        },
        //通过
        Applylist(e) {
            opApply({
                id: e.id,
                type: 1
            }).then((res) => {
                if (res.code == 0) {
                    this.$message.success('申请已通过');
                    this.getData();
                }
            });
        },
        //驳回
        reject(e) {
            opApply({
                id: e.id,
                type: 2
            }).then((res) => {
                if (res.code == 0) {
                    this.$message.success('申请已驳回');
                    this.getData();
                }
            });
        },
        // 触发搜索按钮
        handleSearch() {
            console.log(this.name, '店铺名称');
            // if (this.name == '') {
            //     this.getData();
            // }
            apply({
                page: 1,
                pageNum: 15,
                status: this.status,
                shopName: this.name
            }).then((res) => {
                console.log(res.data.list);
                this.tableData = res.data.list;
                this.pageTotal = res.data.count || 50;
            });
            // this.getData();
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.green {
    color: rgb(38, 141, 38);
}
.red {
    color: red;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
